/**
 * 
 */
package net.microlinktech.testing.codec;


/**
 * @author zhangqing
 *
 */
public class StringSubstring {
	
	/**
	 * 获取小数点后位
	 * @param params
	 * @return
	 */
	public String splitNext(String params,int nextNum) {
		if (params != null && params.indexOf(".") != -1) {
			params = params.substring(params.indexOf(".")+1, params.length());
		}
		if(params.length()- params.indexOf(".") -1 > nextNum){
			params = params.substring(params.indexOf(".")+1,nextNum);
		}
		else if(params.length()- params.indexOf(".") -1 < nextNum)
		{
			String tmpStr2 = "";
			for(int i = 0;i < nextNum-(params.length()- params.indexOf(".") -1);i++){
				tmpStr2 = tmpStr2 + "0";
			}
			params = params+ tmpStr2;
		}
		else{
			params = params.substring(params.indexOf(".")+1, params.length());
		}			
		return params;
	}
	
	/**
	 * 取整数部分
	 * @param params
	 * @param nextNum
	 * @return
	 */
	public String split(String params, int nextNum) {
		int length = params.indexOf(".");
		if(length < nextNum){
			String tmpStr = "";
			for(int i = 0;i < nextNum-length;i++){
				tmpStr = tmpStr + "0";
			}
			params = tmpStr + params;
			params = params.substring(0,nextNum);
		}
		else
			params = params.substring(0,nextNum);
		return params;
	}
	
	/**
	 * 高位补零方法
	 * @param inputStr
	 * @param length
	 * @return
	 */
	public String getStringByLength(String inputStr,int length)
	{
		String tmpStr2 = inputStr;
		if(tmpStr2.length()<length)
		{
			String tmpStr = "";
			for(int i = 0;i < length- tmpStr2.length();i++)
			{
				tmpStr+= "0";	
			}
			tmpStr2 = tmpStr+ tmpStr2;
		}
		return tmpStr2;
	}

}
